It is difficult to come up with unit tests for the statistical funcitons included in bigtime. For these reasons, this document represents an informal but yet unified way to test the package after larger updates.
library(bigtime)
rm(list = ls())
######### settings ############################################################
seed <- 6150533
######### simulating data (no sparsity) #######################################
k <- 2
p <- 2
periods <- 250
max_abs_eigval <- 0.8
e_dist <- function(n) rnorm(n, mean = 0, sd = 0.001)
sim_dat <- simVAR(periods = periods, k = k, p = p, e_dist = e_dist,
seed = seed, max_abs_eigval = max_abs_eigval)
Tests for the coefficient matrix exist. We hence only need to focus on the statistical parts of the data simulation, like e_dist and whether we truly have the VAR we were expecting
# Checking e_dist
e <- sim_dat$e_dist[1:k, ]
e_mu <- apply(e, 1, mean) # should be close to true mean
e_sd <- apply(e, 1, sd) # should be close to true sd
cat(paste("True/Est\t Mean:", 0, " / ", e_mu, "\t SD:", 0.001, " / ", e_sd, "\n"), sep = "")
## True/Est Mean: 0 / 6.49629185507475e-05 SD: 0.001 / 0.00095338832571691
## True/Est Mean: 0 / -6.256021970254e-05 SD: 0.001 / 0.000990030002170774
# Checking the VAR visually
plot.ts(sim_dat$Y)
# Checking whether we can recover the VAR
require(vars)
## Loading required package: vars
## Loading required package: MASS
## Loading required package: strucchange
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: sandwich
## Loading required package: urca
## Loading required package: lmtest
mod <- vars::VAR(sim_dat$Y, p = p, type = "const")
true.coefs <- capture.output(print(cbind(sim_dat$coef_mat[1:k, ], sim_dat$const[1:k])))
est.coefs <- capture.output(print(vars::Bcoef(mod)))
cat("True", true.coefs, "Estimated", est.coefs, sep = "\n")
## True
## Y1.L1 Y2.L1 Y1.L2 Y2.L2
## Y1 0.5406856 0.15836010 -0.10940003 0.01065473 0
## Y2 0.6938092 0.02667691 -0.04031227 0.38677612 0
## Estimated
## Y1.l1 Y2.l1 Y1.l2 Y2.l2 const
## Y1 0.5755576 0.18694100 -0.19155161 0.02873953 0.0001048723
## Y2 0.6321978 0.05428847 0.09773363 0.36677059 -0.0001004079
######### simulating data (lasso) #############################################
k <- 3
p <- 3
periods <- 250
max_abs_eigval <- 0.8
e_dist <- function(n) rnorm(n, mean = 0, sd = 0.001)
sim_dat <- simVAR(periods = periods, k = k, p = p, e_dist = e_dist,
seed = seed, max_abs_eigval = max_abs_eigval,
sparsity_pattern = "lasso",
sparsity_options = list(num_zeroes = 15))
# We can simply check the coefficient matrix on whether it has the right struct.
print(sim_dat$coef_mat[1:k, ])
## Y1.L1 Y2.L1 Y3.L1 Y1.L2 Y2.L2 Y3.L2 Y1.L3
## Y1 0.0000000 0.06657832 0.0000000 0 0.0000000 0.7003966 0.18346332
## Y2 1.7315592 -0.54606547 0.0000000 0 -0.4176549 0.0000000 -0.09649889
## Y3 0.3952238 0.00000000 -0.1789437 0 0.0000000 0.0000000 0.00000000
## Y2.L3 Y3.L3
## Y1 0.03613677 0.0568589
## Y2 0.13164874 0.0000000
## Y3 0.00000000 0.0000000
print(sum(sim_dat$coef_mat[1:k, ] == 0))
## [1] 15
######### simulating data (hvar) ##############################################
k <- 3
p <- 3
periods <- 250
max_abs_eigval <- 0.8
e_dist <- function(n) rnorm(n, mean = 0, sd = 0.001)
sim_dat <- simVAR(periods = periods, k = k, p = p, e_dist = e_dist,
seed = seed, max_abs_eigval = max_abs_eigval,
sparsity_pattern = "hvar",
sparsity_options = list(
zero_min = 0,
zero_max = 3,
zeroes_in_self = TRUE
))
# Inspecting the coef_mat
print(sim_dat$coef_mat[1:k, ])
## Y1.L1 Y2.L1 Y3.L1 Y1.L2 Y2.L2 Y3.L2
## Y1 0.0000000 0.03395399 0.02712238 0.00000000 0.0000000 0.3571923
## Y2 0.8830705 -0.27848561 0.98456632 0.00000000 -0.2129980 0.0000000
## Y3 0.2015585 -0.10261778 0.00000000 -0.09325609 0.2184676 0.0000000
## Y1.L3 Y2.L3 Y3.L3
## Y1 0.00000000 0.00000000 0.02899723
## Y2 0.00000000 0.06713898 0.00000000
## Y3 -0.01215669 0.10518535 0.00000000
######### simulating univariate data ##########################################
k <- 1
p <- 3
periods <- 250
max_abs_eigval <- 0.8
e_dist <- function(n) rnorm(n, mean = 0, sd = 0.001)
sim_dat <- simVAR(periods = periods, k = k, p = p, e_dist = e_dist,
seed = seed, max_abs_eigval = max_abs_eigval,
sparsity_pattern = "hvar",
sparsity_options = list(
zero_min = 0,
zero_max = 3,
zeroes_in_self = TRUE
))
sim_dat$coef_mat
## Y1.L1 Y1.L2 Y1.L3
## Y1 0.5193804 0.2221568 0
## 1.0000000 0.0000000 0
## 0.0000000 1.0000000 0
plot.ts(sim_dat$Y)
######### Estimation (hvar) ###################################################
k <- 3
p <- 3
periods <- 250
max_abs_eigval <- 0.8
e_dist <- function(n) rnorm(n, mean = 0, sd = 0.001)
sim_dat <- simVAR(periods = periods, k = k, p = p, e_dist = e_dist,
seed = seed, max_abs_eigval = max_abs_eigval,
sparsity_pattern = "hvar",
sparsity_options = list(
zero_min = 0,
zero_max = 3,
zeroes_in_self = TRUE
))
# Using no selection at all
hvar <- sparseVAR(scale(sim_dat$Y))
# hvar should not use any selection method.
# Thus selection should be none and phis should be a 3d array
hvar$selection
## [1] "none"
dim(hvar$Phihat)
## [1] 3 69 10
dim(hvar$phi0hat)
## [1] 3 1 10
hvar <- sparseVAR(sim_dat$Y) # This should give a standardisation warning
## Warning in .check_if_standardised(Y): It is recommended to standardise your data
## such that all variables have unit standard deviation
## Warning in .check_if_standardised(Y): It is recommended to standardise your data
## such that all variables have zero mean.
# Using cv selection
hvar <- sparseVAR(scale(sim_dat$Y), selection = "cv")
# selection field should be cv, lambda opt and lambda SE opt should be given
# and phis should be matrix/vector
hvar$selection
## [1] "cv"
dim(hvar$Phihat)
## [1] 3 69
length(hvar$phi0hat)
## [1] 3
hvar$lambda_opt
## [1] 4.352955
hvar$lambda_SEopt
## [1] 12.11236
# using bic
hvar <- sparseVAR(scale(sim_dat$Y), selection = "bic")
##
##
## #### Selected the following ####
##
## AIC BIC HQ
## 7.261167 12.112356 12.112356
##
##
## #### Details ####
##
## lambda AIC BIC HQ
## 1 156.4371 -0.1117 -0.1117 -0.1117
## 2 93.7816 -0.475 -0.461 -0.4694
## 3 56.2206 -0.896 -0.8256 -0.8676
## 4 33.7033 -1.3422 -1.1732 -1.2742
## 5 20.2046 -1.6734 -1.5043 -1.6053
## 6 12.1124 -1.8336 ==> -1.6505 ==> -1.7599
## 7 7.2612 ==> -1.8491 -1.5533 -1.7301
## 8 4.353 -1.3553 -0.0734 -0.8394
## 9 2.6095 -0.7489 1.8852 0.3112
## 10 1.5644 -0.8258 2.0759 0.342
# selection should be bic, and phis should be matrix/vector
# lambda opt should contain bic opt choice
# verbose is always true, so output should be shown comparing different lambdas
# and ic
hvar$selection
## [1] "bic"
hvar$lambda_opt
## [1] 12.11236
hvar$lambda_SEopt # This should be NA
## [1] NA
dim(hvar$Phihat)
## [1] 3 69
length(hvar$phi0hat)
## [1] 3
# using aic
hvar <- sparseVAR(scale(sim_dat$Y), selection = "aic")
##
##
## #### Selected the following ####
##
## AIC BIC HQ
## 7.261167 12.112356 12.112356
##
##
## #### Details ####
##
## lambda AIC BIC HQ
## 1 156.4371 -0.1117 -0.1117 -0.1117
## 2 93.7816 -0.475 -0.461 -0.4694
## 3 56.2206 -0.896 -0.8256 -0.8676
## 4 33.7033 -1.3422 -1.1732 -1.2742
## 5 20.2046 -1.6734 -1.5043 -1.6053
## 6 12.1124 -1.8336 ==> -1.6505 ==> -1.7599
## 7 7.2612 ==> -1.8491 -1.5533 -1.7301
## 8 4.353 -1.3553 -0.0734 -0.8394
## 9 2.6095 -0.7489 1.8852 0.3112
## 10 1.5644 -0.8258 2.0759 0.342
# selection should be aic, and phis should be matrix/vector
# lambda opt should contain aic opt choice
# verbose is always true, so output should be shown comparing different lambdas
# and ic
hvar$selection
## [1] "aic"
hvar$lambda_opt
## [1] 7.261167
hvar$lambda_SEopt # This should be NA
## [1] NA
dim(hvar$Phihat)
## [1] 3 69
length(hvar$phi0hat)
## [1] 3
# using hq
hvar <- sparseVAR(scale(sim_dat$Y), selection = "hq")
##
##
## #### Selected the following ####
##
## AIC BIC HQ
## 7.261167 12.112356 12.112356
##
##
## #### Details ####
##
## lambda AIC BIC HQ
## 1 156.4371 -0.1117 -0.1117 -0.1117
## 2 93.7816 -0.475 -0.461 -0.4694
## 3 56.2206 -0.896 -0.8256 -0.8676
## 4 33.7033 -1.3422 -1.1732 -1.2742
## 5 20.2046 -1.6734 -1.5043 -1.6053
## 6 12.1124 -1.8336 ==> -1.6505 ==> -1.7599
## 7 7.2612 ==> -1.8491 -1.5533 -1.7301
## 8 4.353 -1.3553 -0.0734 -0.8394
## 9 2.6095 -0.7489 1.8852 0.3112
## 10 1.5644 -0.8258 2.0759 0.342
# selection should be hq, and phis should be matrix/vector
# lambda opt should contain hq opt choice
# verbose is always true, so output should be shown comparing different lambdas
# and ic
hvar$selection
## [1] "hq"
hvar$lambda_opt
## [1] 12.11236
hvar$lambda_SEopt # This should be NA
## [1] NA
dim(hvar$Phihat)
## [1] 3 69
length(hvar$phi0hat)
## [1] 3
######### Estimation (lasso) ##################################################
# If above looks all good, then we can check whether all also works for lasso
# no selection method
lasso <- sparseVAR(scale(sim_dat$Y), selection = "none", VARpen = "L1")
lasso$selection
## [1] "none"
dim(lasso$Phihat)
## [1] 3 69 10
dim(lasso$phi0hat)
## [1] 3 1 10
# cv selection
lasso <- sparseVAR(scale(sim_dat$Y), selection = "cv", VARpen = "L1")
lasso$selection
## [1] "cv"
lasso$lambda_opt
## [1] 12.11153
lasso$lambda_SEopt
## [1] 20.20325
dim(lasso$Phihat)
## [1] 3 69
length(lasso$phi0hat)
## [1] 3
# only checking bic selection
lasso <- sparseVAR(scale(sim_dat$Y), selection = "bic", VARpen = "L1")
##
##
## #### Selected the following ####
##
## AIC BIC HQ
## 12.11153 20.20325 12.11153
##
##
## #### Details ####
##
## lambda AIC BIC HQ
## 1 156.4265 -0.1117 -0.1117 -0.1117
## 2 93.7752 -0.4677 -0.4254 -0.4507
## 3 56.2168 -1.0448 -0.9462 -1.0051
## 4 33.7011 -1.4746 -1.3337 -1.4179
## 5 20.2033 -1.7398 ==> -1.4581 -1.6264
## 6 12.1115 ==> -1.8455 -1.3244 ==> -1.6358
## 7 7.2607 -1.7657 -0.667 -1.3235
## 8 4.3527 -1.6221 0.1105 -0.9248
## 9 2.6094 -1.5431 0.5979 -0.6814
## 10 1.5643 -1.4401 1.0672 -0.431
lasso$selection
## [1] "bic"
lasso$lambda_opt
## [1] 20.20325
lasso$lambda_SEopt
## [1] NA
dim(lasso$Phihat)
## [1] 3 69
length(lasso$phi0hat)
## [1] 3
######### VAR diagnostics #####################################################
k <- 3
p <- 3
periods <- 250
max_abs_eigval <- 0.8
e_dist <- function(n) rnorm(n, mean = 0, sd = 0.001)
sim_dat <- simVAR(periods = periods, k = k, p = p, e_dist = e_dist,
seed = seed, max_abs_eigval = max_abs_eigval,
sparsity_pattern = "hvar",
sparsity_options = list(
zero_min = 0,
zero_max = 3,
zeroes_in_self = TRUE
))
hvar <- sparseVAR(scale(sim_dat$Y), selection = "none")
try({plot_cv(hvar)}) # Should give an error because model did not use cv
## Error in plot_cv(hvar) :
## No cross-validation was used in model estimation. Set selection='cv' in sparseVAR
try({diagnostics_plot(hvar)}) # This should not work and should give an error
## Error in diagnostics_plot.bigtime.VAR(hvar) :
## Cannot be used with selection='none'. Choose other selection procedure in sparseVAR or call ic_selection on model first.
res <- residuals(hvar)
dim(res) # Should be a 3d array
## [1] 227 3 10
fit <- fitted(hvar)
dim(fit) # Should have same dimensions as res
## [1] 227 3 10
try({lagmat <- lagmatrix(hvar, returnplot = TRUE)}) # This should not work
## Error in lagmatrix(hvar, returnplot = TRUE) :
## Model did not use any selection procedure. Please use a selection procedure in sparseVAR or call ic_selection on model first.
hvar <- sparseVAR(scale(sim_dat$Y), selection = "cv")
plot_cv(hvar) # This should work
diagnostics_plot(hvar) # This should work and plot for the first series
res <- resid(hvar) # Can also be used instead of residuals
dim(res) # Should be a matrix. If it works for this it will also work for all IC selections
## [1] 227 3
fit <- fitted(hvar)
dim(fit) # Should have same dimensions as res
## [1] 227 3
lagmat <- lagmatrix(hvar, returnplot = TRUE) # This should work just fine.
hvar <- sparseVAR(scale(sim_dat$Y), selection = "bic")
##
##
## #### Selected the following ####
##
## AIC BIC HQ
## 7.261167 12.112356 12.112356
##
##
## #### Details ####
##
## lambda AIC BIC HQ
## 1 156.4371 -0.1117 -0.1117 -0.1117
## 2 93.7816 -0.475 -0.461 -0.4694
## 3 56.2206 -0.896 -0.8256 -0.8676
## 4 33.7033 -1.3422 -1.1732 -1.2742
## 5 20.2046 -1.6734 -1.5043 -1.6053
## 6 12.1124 -1.8336 ==> -1.6505 ==> -1.7599
## 7 7.2612 ==> -1.8491 -1.5533 -1.7301
## 8 4.353 -1.3553 -0.0734 -0.8394
## 9 2.6095 -0.7489 1.8852 0.3112
## 10 1.5644 -0.8258 2.0759 0.342
try({plot_cv(hvar)}) # Should not work
## Error in plot_cv(hvar) :
## No cross-validation was used in model estimation. Set selection='cv' in sparseVAR
diagnostics_plot(hvar, variable = 2) # This should work and plot for the second series
lagmat <- lagmatrix(hvar, returnplot = TRUE) # This should work just fine. If it works here, it also works for the followign
hvar <- sparseVAR(scale(sim_dat$Y), selection = "aic")
##
##
## #### Selected the following ####
##
## AIC BIC HQ
## 7.261167 12.112356 12.112356
##
##
## #### Details ####
##
## lambda AIC BIC HQ
## 1 156.4371 -0.1117 -0.1117 -0.1117
## 2 93.7816 -0.475 -0.461 -0.4694
## 3 56.2206 -0.896 -0.8256 -0.8676
## 4 33.7033 -1.3422 -1.1732 -1.2742
## 5 20.2046 -1.6734 -1.5043 -1.6053
## 6 12.1124 -1.8336 ==> -1.6505 ==> -1.7599
## 7 7.2612 ==> -1.8491 -1.5533 -1.7301
## 8 4.353 -1.3553 -0.0734 -0.8394
## 9 2.6095 -0.7489 1.8852 0.3112
## 10 1.5644 -0.8258 2.0759 0.342
try({plot_cv(hvar)}) # Should not work
## Error in plot_cv(hvar) :
## No cross-validation was used in model estimation. Set selection='cv' in sparseVAR
diagnostics_plot(hvar, variable = 3) # This should work and plot for the third series
hvar <- sparseVAR(scale(sim_dat$Y), selection = "hq")
##
##
## #### Selected the following ####
##
## AIC BIC HQ
## 7.261167 12.112356 12.112356
##
##
## #### Details ####
##
## lambda AIC BIC HQ
## 1 156.4371 -0.1117 -0.1117 -0.1117
## 2 93.7816 -0.475 -0.461 -0.4694
## 3 56.2206 -0.896 -0.8256 -0.8676
## 4 33.7033 -1.3422 -1.1732 -1.2742
## 5 20.2046 -1.6734 -1.5043 -1.6053
## 6 12.1124 -1.8336 ==> -1.6505 ==> -1.7599
## 7 7.2612 ==> -1.8491 -1.5533 -1.7301
## 8 4.353 -1.3553 -0.0734 -0.8394
## 9 2.6095 -0.7489 1.8852 0.3112
## 10 1.5644 -0.8258 2.0759 0.342
try({plot_cv(hvar)}) # Should not work
## Error in plot_cv(hvar) :
## No cross-validation was used in model estimation. Set selection='cv' in sparseVAR
diagnostics_plot(hvar, variable = 'Y2') # This should work and plot for the second series
try({diagnostics_plot(hvar, variable = 4)}) # This should not work since only 3 series are estimated
## Error in .diagnostics_plot(Y, fit, res, s, variable, dates) :
## Data does not have 4 columns, but only 3
try({diagnostics_plot(hvar, variable = "Y4")}) # This should not work since only 3 series are estimated
## Error in .diagnostics_plot(Y, fit, res, s, variable, dates) :
## Data has no variable called Y4
# It should also all work if we use lasso instead
hvar <- sparseVAR(scale(sim_dat$Y), selection = "cv", VARpen = "L1")
plot_cv(hvar) # This should work
diagnostics_plot(hvar) # This should work and plot for the first series
res <- resid(hvar) # Can also be used instead of residuals
dim(res) # Should be a matrix. If it works for this it will also work for all IC selections
## [1] 227 3
fit <- fitted(hvar)
dim(fit) # Should have same dimensions as res
## [1] 227 3
lagmat <- lagmatrix(hvar, returnplot = TRUE) # This should work just fine.
######### VAR forecasting #####################################################
k <- 3
p <- 3
periods <- 250
max_abs_eigval <- 0.8
e_dist <- function(n) rnorm(n, mean = 0, sd = 0.001)
sim_dat <- simVAR(periods = periods, k = k, p = p, e_dist = e_dist,
seed = seed, max_abs_eigval = max_abs_eigval,
sparsity_pattern = "hvar",
sparsity_options = list(
zero_min = 0,
zero_max = 3,
zeroes_in_self = TRUE
))
# doing it for hvar
mod <- sparseVAR(scale(sim_dat$Y), selection = "none")
dir_fcst <- directforecast(mod)
dim(dir_fcst) # This should be a 3d array
## [1] 1 3 10
rec_fcst <- recursiveforecast(mod, h = 5) # message should be given saying all lambdas are used for forecasting
## Forecasting using all lambdas
dim(rec_fcst$fcst) # This should be a 3d array
## [1] 5 3 10
plot(rec_fcst) # This should plot a ribbon covering the min to max forecast at each horizon
## Cube has no column names. Defaulting to Y...
## Plotting ribbon from min to max because multiple lambdas are used
# Same should work if lasso is done
mod <- sparseVAR(scale(sim_dat$Y), selection = "none", VARpen = "L1")
dir_fcst <- directforecast(mod)
dim(dir_fcst) # This should be a 3d array
## [1] 1 3 10
rec_fcst <- recursiveforecast(mod, h = 5) # message should be given saying all lambdas are used for forecasting
## Forecasting using all lambdas
dim(rec_fcst$fcst) # This should be a 3d array
## [1] 5 3 10
plot(rec_fcst) # This should plot a ribbon covering the min to max forecast at each horizon
## Cube has no column names. Defaulting to Y...
## Plotting ribbon from min to max because multiple lambdas are used
# selecting using cv and any ic should behave same and thus only cv is tested
mod <- sparseVAR(scale(sim_dat$Y), selection = "cv")
dir_fcst <- directforecast(mod)
length(dir_fcst) # This should be a vector
## [1] 3
rec_fcst <- recursiveforecast(mod, h = 5)
dim(rec_fcst$fcst) # This should be a matrix
## [1] 5 3
plot(rec_fcst) # Should plot a line since only one lambda is used
###### Testing univariate functionality #######################################
k <- 1
p <- 3
periods <- 250
max_abs_eigval <- 0.8
e_dist <- function(n) rnorm(n, mean = 0, sd = 0.001)
sim_dat <- simVAR(periods = periods, k = k, p = p, e_dist = e_dist,
seed = seed, max_abs_eigval = max_abs_eigval,
sparsity_pattern = "hvar",
sparsity_options = list(
zero_min = 0,
zero_max = 3,
zeroes_in_self = TRUE))
## Estimation using none
mod <- sparseVAR(scale(sim_dat$Y), selection = "none")
dim(mod$phi0hat)
## [1] 1 1 10
dim(mod$Phihat)
## [1] 1 23 10
fit <- fitted(mod)
dim(fit)
## [1] 227 1 10
res <- residuals(mod)
dim(res)
## [1] 227 1 10
max(abs(fit + res - mod$Y[-(1:mod$p), ])) # this should be zero
## [1] 4.440892e-16
try({plot_cv(mod)}) # this should throw an error
## Error in plot_cv(mod) :
## No cross-validation was used in model estimation. Set selection='cv' in sparseVAR
try({diagnostics_plot(mod)}) # this should also throw an error
## Error in diagnostics_plot.bigtime.VAR(mod) :
## Cannot be used with selection='none'. Choose other selection procedure in sparseVAR or call ic_selection on model first.
## Estimation using cv
mod <- sparseVAR(scale(sim_dat$Y), selection = "cv")
dim(mod$phi0hat)
## NULL
length(mod$phi0hat)
## [1] 1
dim(mod$Phihat)
## NULL
length(mod$Phihat)
## [1] 23
fit <- fitted(mod)
res <- residuals(mod)
max(abs(fit + res - mod$Y[-(1:mod$p), ]))
## [1] 4.440892e-16
plot_cv(mod)
diagnostics_plot(mod, variable = 1)
## Estmimation using bic, aic, hq
mod <- sparseVAR(scale(sim_dat$Y), selection = "bic")
##
##
## #### Selected the following ####
##
## AIC BIC HQ
## 4.292028 4.292028 4.292028
##
##
## #### Details ####
##
## lambda AIC BIC HQ
## 1 154.2475 0.041 0.041 0.041
## 2 92.469 -0.2747 -0.2606 -0.269
## 3 55.4337 -0.4271 -0.3989 -0.4158
## 4 33.2316 -0.5014 -0.4732 -0.4901
## 5 19.9218 -0.5325 -0.5043 -0.5212
## 6 11.9428 -0.5446 -0.5164 -0.5332
## 7 7.1595 -0.5491 -0.521 -0.5378
## 8 4.292 ==> -0.5504 ==> -0.5223 ==> -0.5391
## 9 2.573 -0.3998 -0.0899 -0.2751
## 10 1.5425 -0.4208 -0.111 -0.2961
mod <- sparseVAR(scale(sim_dat$Y), selection = "aic")
##
##
## #### Selected the following ####
##
## AIC BIC HQ
## 4.292028 4.292028 4.292028
##
##
## #### Details ####
##
## lambda AIC BIC HQ
## 1 154.2475 0.041 0.041 0.041
## 2 92.469 -0.2747 -0.2606 -0.269
## 3 55.4337 -0.4271 -0.3989 -0.4158
## 4 33.2316 -0.5014 -0.4732 -0.4901
## 5 19.9218 -0.5325 -0.5043 -0.5212
## 6 11.9428 -0.5446 -0.5164 -0.5332
## 7 7.1595 -0.5491 -0.521 -0.5378
## 8 4.292 ==> -0.5504 ==> -0.5223 ==> -0.5391
## 9 2.573 -0.3998 -0.0899 -0.2751
## 10 1.5425 -0.4208 -0.111 -0.2961
mod <- sparseVAR(scale(sim_dat$Y), selection = "hq")
##
##
## #### Selected the following ####
##
## AIC BIC HQ
## 4.292028 4.292028 4.292028
##
##
## #### Details ####
##
## lambda AIC BIC HQ
## 1 154.2475 0.041 0.041 0.041
## 2 92.469 -0.2747 -0.2606 -0.269
## 3 55.4337 -0.4271 -0.3989 -0.4158
## 4 33.2316 -0.5014 -0.4732 -0.4901
## 5 19.9218 -0.5325 -0.5043 -0.5212
## 6 11.9428 -0.5446 -0.5164 -0.5332
## 7 7.1595 -0.5491 -0.521 -0.5378
## 8 4.292 ==> -0.5504 ==> -0.5223 ==> -0.5391
## 9 2.573 -0.3998 -0.0899 -0.2751
## 10 1.5425 -0.4208 -0.111 -0.2961
mod$selection
## [1] "hq"
mod$lambda_opt
## [1] 4.292028
try({plot_cv(mod)}) # This should throw an error
## Error in plot_cv(mod) :
## No cross-validation was used in model estimation. Set selection='cv' in sparseVAR
diagnostics_plot(mod)